<?php 
/**
* 
*/
class Pagination
{
  public static function getPagination( $totalItems, $currentPage, $itemPerPage )
  {
    if($itemPerPage != 0)
      $nbPages = ceil($totalItems/$itemPerPage);
    else
      $nbPages = 0;

    $adjacents = Config::$nbValeursPagination;
    $result = array();

    if (isset($totalItems, $itemPerPage))
    {
        $result = range(1, ceil($totalItems / $itemPerPage));
        if (isset($currentPage, $adjacents))
        {
            if (($adjacents = floor($adjacents / 2) * 2 + 1) >= 1)
            {
                $result = array_slice($result, max(0, min(count($result) - $adjacents, intval($currentPage) - ceil($adjacents / 2))), $adjacents);
            }
        }
    }

    return array('nbPages' => $nbPages, 'currentPage' => $currentPage, 'pages' => $result);
  }
}
?>